﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace BPC.Magic8Ball.Test
{
    [TestFixture]
    public class Ball
    {
        Magic8Ball.Ball ball;
        string answer;

        [SetUp]
        public void SetUp()
        {
            //Arrange
            ball = new BPC.Magic8Ball.Ball();
            answer = "";
        }

        [Test]
        public void ShouldReturnAnAnswerWhenAskedQuestion()
        {

            //Act
            answer = ball.AskQuestion("Will the work?");

            //Assert
            Assert.IsNotNull(answer);
        }

        [Test]
        public void ShouldReturnAValidAnswerWhenAskedQuestion()
        { 
        
            //Act
            answer = ball.AskQuestion("A different question");

            //Assert
            Assert.Contains(answer, ball.Answers);
        }

        [Test]
        public void ShouldReturnAnswerFromCustomAnswer()
        { 
        
            //Arrange
            ball.Answers = new List<string>() {"Custom Answer"};

            //Act
            answer = ball.AskQuestion("Give me a custome answer");

            //Assert
            Assert.AreEqual("Custom Answer", answer);
        }

        [Test]
        public void ShouldReturnAMixOfAnswerFromCustomQuestions()
        {
            //Arrange
            ball.Answers = new List<string>() { "One", "Two", "Three" };
            int one = 0;
            int two = 0;
            int three = 0;

            //Act
            for (int i = 0; i < 100000; i++)
            {
                answer = ball.AskQuestion(i.ToString());
                if (answer == "One") one++;
                if (answer == "Two") two++;
                if (answer == "Three") three++;
            }

            //Assert
            Assert.AreNotEqual(0, one, "One");
            Assert.AreNotEqual(0, two, "Two");
            Assert.AreNotEqual(0, three, "Three");
        }
    }
}
